/*
 * Copyright 2012 The University of Auckland
 */

#include "modules/mod_sampler2d.frag"
#include "modules/mod_filtering.frag"

uniform sampler2D colorTex_;
uniform sampler2D depthTex_;
uniform TextureParameters textureParameters_;

uniform float saturation_;

void main() {
    // lookup input color and depth value (see mod_sampler2d.frag)
    vec4 color = textureLookup2Dscreen(colorTex_, textureParameters_, gl_FragCoord.xy);
    float depth = textureLookup2Dscreen(depthTex_, textureParameters_, gl_FragCoord.xy).z;

    // compute gray value (see mod_filtering.frag) and pass-through depth value
    FragData0 = rgbToGrayScaleSaturated(color, saturation_);
    gl_FragDepth = depth;
}


/**
 * Bastijns code
 *

// IN PROCESSOR I GUESS
delete optTex_;
optTex_ = new tgt::Texture( tgt::ivec3(selections_.size(), 6, 1), // dimensions 
							GL_RGBA, // format
							GL_RGBA8, // internal format 
							GL_UNSIGNED_BYTE, // data type 
							tgt::Texture::NEAREST, // filter 
							(!GpuCaps.isNpotSupported()) // is texture rectangle? 
						  );

for (int i = 0; i < selections_.size(); ++i){ 
	optTex_->texel<tgt::col4>(i,0) = tgt::col4(log2((int)options[i])); 
	optTex_->texel<tgt::col4>(i,1) = tgt::col4(selections_.at(i)->getAmbientColor()*255.f); 
	optTex_->texel<tgt::col4>(i,2) = tgt::col4(selections_.at(i)->getDiffuseColor()*255.f); 
	optTex_->texel<tgt::col4>(i,3) = tgt::col4(selections_.at(i)->getSpecularColor()*255.f); 
	optTex_->texel<tgt::col4>(i,4) = tgt::col4(selections_.at(i)->getLightPosition()*255.f); 
}

TextureUnit optUnit; 
optUnit.activate(); 
optTex_->bind(); 
optTex_->uploadTexture(); 
sh->setUniform("optTex_", optUnit.getUnitNumber()); 
sh->setIgnoreUniformLocationError(true); 
sh->setUniform("optTexParameters_.dimensions_", tgt::vec2(optTex_->getDimensions().xy())); 
sh->setUniform("optTexParameters_.dimensionsRCP_", tgt::vec2(1.0f) / tgt::vec2(optTex_->getDimensions().xy()));
sh->setUniform("optTexParameters_.matrix_", tgt::mat4::identity); 
sh->setIgnoreUniformLocationError(false);


// IN SHADER
uniform SAMPLER2D_TYPE optTex_; 
uniform TEXTURE_PARAMETERS optTexParameters_;

 raycasting loop ..{ 
 	color.rgb = textureLookup2D(optTex_, optTexParameters_, vec2(3,2)).rgb; 
 	color.a = 1.0;
 }
 
 // SIMPLE VALUE SETUP
for (int i = 0; i < selections_.size(); ++i){ 
	optTex_->texel<tgt::col4>(i,0) = tgt::col4(1); 
	optTex_->texel<tgt::col4>(i,1) = tgt::col4(50); 
	optTex_->texel<tgt::col4>(i,2) = tgt::col4(100); 
	optTex_->texel<tgt::col4>(i,3) = tgt::col4(150); 
	optTex_->texel<tgt::col4>(i,4) = tgt::col4(200); 
}
 */
